/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daios.wsdl.parser;

import java.net.URL;
import java.util.Hashtable;
import java.util.logging.Logger;

import javax.wsdl.Definition;

import at.ac.tuwien.infosys.dsg.daios.framework.interfaces.IConstants;
import at.ac.tuwien.infosys.dsg.daios.wsdl.typesystem.WSDLTypeTree;

/**
 * Abstract class defining a factory for creating Daios type systems
 * from WSDL definitions. The factory decides on the used invocation
 * style (RPC or document) on the actual type parser to use to construct
 * the type system.
 * 
 * @author philipp
 *
 */
public abstract class TypeParser {
	
	protected Logger log = Logger.getLogger(IConstants.LOG_NAME);
	
	private static Hashtable<String,TypeParser> mappings = null;
	
	static {
		
		mappings = new Hashtable<String,TypeParser>();
		mappings.put(IConstants.DOC_STYLE, new SOAPUIParser());
		mappings.put(IConstants.RPC_STYLE, new SOAPUIParser());
	}
	
	/**
	 * Return a concrete type parser instance that is registered to handle a given
	 * invocation style. Possible styles are 'document' and
	 * 'rpc'.
	 * 
	 * @param style The style that you want an parser instance for.
	 * @return The parser.
	 */
	public static TypeParser getInstance(String style) {
		
		return mappings.get(style);
		
	}
	
	/**
	 * Construct the type tree from a  given WSDL definition.
	 * 
	 * @param wsdl The WSDL definition.
	 * @param location The URL where the WSDL can be found. This
	 * is necessary so that relative URLs can be followed by the
	 * parser.
	 * @param style The invocation style to use. Possible values
	 * are 'document' and 'rpc'.
	 * @return The entirely parsed type tree.
	 */
	public abstract WSDLTypeTree getElementTypes(Definition wsdl,
			URL location, String style);
	
}
